﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace pdftron.PDF.Tools.Utilities
{
    public sealed partial class AuthorInputDialog : UserControl, IAuthorDialog
    {
        public string AuthorName
        {
            get { return AuthorNameTextBox.Text; }
            set { AuthorNameTextBox.Text = value; }
        }

        //public delegate void OnButtonClickedHandler(bool wasOkSelected);
        public event OnButtonClickedHandler OnButtonClicked;

        public AuthorInputDialog()
        {
            this.InitializeComponent();
            this.Loaded += AuthorInputDialog_Loaded;
            
#if WINDOWS_PHONE_APP
            Window.Current.SizeChanged += Current_SizeChanged;
            HandleSize(Window.Current.Bounds.Width, Window.Current.Bounds.Height);
#endif // WINDOWS_PHONE_APP
        }

        void AuthorInputDialog_Loaded(object sender, RoutedEventArgs e)
        {
            //IronOne Technologies (Pvt) Ltd
            //2015-06-20
            //Below line is commentd by us.
            //AuthorNameTextBox.Focus(FocusState.Programmatic);

            //IronOne Technologies (Pvt) Ltd
            //2015-06-20
            //This is added to remove this dialog been poped up.
            if (OnButtonClicked != null)
            {
                OnButtonClicked(this, false);
            }
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (OnButtonClicked != null)
            {
                OnButtonClicked(this, true);
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            if (OnButtonClicked != null)
            {
                OnButtonClicked(this, false);
            }
        }

        public void Show()
        {

        }

        public void Hide()
        {

        }


        void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
        {
            HandleSize(e.Size.Width, e.Size.Height);
        }


        private void HandleSize(double width, double height)
        {
            if (width < 500)
            {
                VisualStateManager.GoToState(this, "NarrowLayout", true);
            }
            else if (height < 500)
            {
                VisualStateManager.GoToState(this, "FlatLayout", true);
            }
        }
    }
}
